package com.interview.javabase.algorithm;

import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @description:
 * @author: zhangshuguang@vichain.com
 * @date: 2019/06/12 15:19
 */
@SpringBootTest
public class Demo2 {

    @Test
    public void solution1() {
        int  key = 100;

        int  tem = 0;
        // 先去找到平方数小于key的数
        for (int i = 1; i <= key; i++) {
            if (key <= i * i) {
                tem = i;
                break;
            }
        }

        for (int i = 1; i <= tem; i++) {
            for (int j = i + 1; j <= tem; j++) {
                if (i * i + j * j == key) {
                    System.out.println(i + "*" + i + "+" + j + "*" + j + "=" + key);
                    break;
                }
            }
        }
    }


    @Test
    public void solution2() {
        int  key = 100;

        // 先去找到平方数小于key的数
        int tem = (int )Math.sqrt(key);

        for (int i = 1; i <= tem; i++) {
            for (int j = i + 1; j <= tem; j++) {
                if (i * i + j * j == key) {
                    System.out.println(i + "*" + i + "+" + j + "*" + j + "=" + key);
                    break;
                }
            }
        }
    }
}
